package SAC;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import org.w3c.dom.Document;

import Helpers.ApplicationConfiguration;


public class SACManager {
	private static final class Nested
    {
        static final SACManager _instance = new SACManager();
    }
	 
	private SACManager()
	{
		 
	}

    public static SACManager getInstance()
    {
          return Nested._instance;
    }

    public Map<String, String[]> GetLayout(String currentGroup, String alias)
    {
    	Map<String, String[]> result = new HashMap<String, String[]>();
    	Map<String, String[]> layout = ApplicationConfiguration.getInstance().GetLayout(alias);

    	Set<Entry<String, String[]>> set = layout.entrySet();
    	
    	Iterator<Entry<String, String[]>> it = set.iterator();
    	
    	while (it.hasNext()) {
			Map.Entry<String, String[]> entry = (Map.Entry<String, String[]>) it.next();
			String accessString = entry.getValue()[1]; 
	        String[] splitedAccessString = accessString.split("|");
	         
	        boolean isGrantAccess = false;
	        for (int i = 0; i < splitedAccessString.length; i++) 
	        {
	        	isGrantAccess = splitedAccessString.equals(currentGroup);
	        }

	        if(accessString == "" || isGrantAccess)
	        {
	        	String[] pathAndMeta = new String[2]; 
	        	pathAndMeta[0] = entry.getValue()[0];
	        	pathAndMeta[1] = entry.getValue()[2];
	        	result.put(entry.getKey(), pathAndMeta);
	        }
		}
    	
    	return result;
    }
}
